File: src\Features\DiagnosticsTestUtilities\CodeActions\CSharpCodeFixVerifier`2.cs
Web Access
Project: src\src\CodeStyle\Core\Tests\UnitTestUtilities\Microsoft.CodeAnalysis.CodeStyle.UnitTestUtilities.csproj (Microsoft.CodeAnalysis.CodeStyle.UnitTestUtilities)
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
 
using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.CSharp.Testing;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Testing;
 
namespace Microsoft.CodeAnalysis.Editor.UnitTests.CodeActions
{
    public static partial class CSharpCodeFixVerifier<TAnalyzer, TCodeFix>
        where TAnalyzer : DiagnosticAnalyzer, new()
        where TCodeFix : CodeFixProvider, new()
    {
        /// <inheritdoc cref="CodeFixVerifier{TAnalyzer, TCodeFix, TTest, TVerifier}.Diagnostic()"/>
        public static DiagnosticResult Diagnostic()
            => CSharpCodeFixVerifier<TAnalyzer, TCodeFix, DefaultVerifier>.Diagnostic();
 
        /// <inheritdoc cref="CodeFixVerifier{TAnalyzer, TCodeFix, TTest, TVerifier}.Diagnostic(string)"/>
        public static DiagnosticResult Diagnostic(string diagnosticId)
            => CSharpCodeFixVerifier<TAnalyzer, TCodeFix, DefaultVerifier>.Diagnostic(diagnosticId);
 
        /// <inheritdoc cref="CodeFixVerifier{TAnalyzer, TCodeFix, TTest, TVerifier}.Diagnostic(DiagnosticDescriptor)"/>
        public static DiagnosticResult Diagnostic(DiagnosticDescriptor descriptor)
            => CSharpCodeFixVerifier<TAnalyzer, TCodeFix, DefaultVerifier>.Diagnostic(descriptor);
 
        /// <summary>
        /// Verify standard properties of <typeparamref name="TAnalyzer"/>.
        /// </summary>
        /// <remarks>
        /// This validation method is largely specific to dotnet/roslyn scenarios.
        /// </remarks>
        public static void VerifyStandardProperty(AnalyzerProperty property)
            => CodeFixVerifierHelper.VerifyStandardProperty(new TAnalyzer(), property);
 
        /// <inheritdoc cref="CodeFixVerifier{TAnalyzer, TCodeFix, TTest, TVerifier}.VerifyAnalyzerAsync(string, DiagnosticResult[])"/>
        public static async Task VerifyAnalyzerAsync(
            [StringSyntax(PredefinedEmbeddedLanguageNames.CSharpTest)] string source, params DiagnosticResult[] expected)
        {
            var test = new Test
            {
                TestCode = source,
            };
 
            test.ExpectedDiagnostics.AddRange(expected);
            await test.RunAsync();
        }
 
        /// <inheritdoc cref="CodeFixVerifier{TAnalyzer, TCodeFix, TTest, TVerifier}.VerifyCodeFixAsync(string, string)"/>
        public static async Task VerifyCodeFixAsync(
            [StringSyntax(PredefinedEmbeddedLanguageNames.CSharpTest)] string source,
            [StringSyntax(PredefinedEmbeddedLanguageNames.CSharpTest)] string fixedSource)
            => await VerifyCodeFixAsync(source, DiagnosticResult.EmptyDiagnosticResults, fixedSource);
 
        /// <inheritdoc cref="CodeFixVerifier{TAnalyzer, TCodeFix, TTest, TVerifier}.VerifyCodeFixAsync(string, DiagnosticResult, string)"/>
        public static async Task VerifyCodeFixAsync(
            [StringSyntax(PredefinedEmbeddedLanguageNames.CSharpTest)] string source,
            DiagnosticResult expected,
            [StringSyntax(PredefinedEmbeddedLanguageNames.CSharpTest)] string fixedSource)
            => await VerifyCodeFixAsync(source, [expected], fixedSource);
 
        /// <inheritdoc cref="CodeFixVerifier{TAnalyzer, TCodeFix, TTest, TVerifier}.VerifyCodeFixAsync(string, DiagnosticResult[], string)"/>
        public static async Task VerifyCodeFixAsync(
            [StringSyntax(PredefinedEmbeddedLanguageNames.CSharpTest)] string source,
            DiagnosticResult[] expected,
            [StringSyntax(PredefinedEmbeddedLanguageNames.CSharpTest)] string fixedSource)
        {
            var test = new Test
            {
                TestCode = source,
                FixedCode = fixedSource,
            };
 
            test.ExpectedDiagnostics.AddRange(expected);
            await test.RunAsync();
        }
    }
}